
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Asynchronous Event Testing</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>

<!--there is no custom header content for this example-->

</head>

<body class=" yui-skin-sam">

<h1>Asynchronous Event Testing</h1>

<div class="exampleIntro">
	<p>This example shows how to create an asynchronous test with the YUI Test framework for testing browser-based JavaScript code. 
  A code>Y.Test.Case</code></a> object is created to test the
  <code>Y.Anim</code> object. The test waits until the animation is complete
  before checking the settings of the animated element.</p>			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<div id="testLogger"></div>
<div id="testDiv" style="position:absolute;width:10px;height:10px; background-color:red"></div>
<script type="text/javascript">
YUI({base:"../../build/", timeout: 10000}).use("anim", "console", "test",function (Y) {

    Y.namespace("example.test");
    
    Y.example.test.AsyncTestCase = new Y.Test.Case({
    
        //name of the test case - if not provided, one is auto-generated
        name : "Animation Tests",        
                
        //---------------------------------------------------------------------
        // Test methods - names must begin with "test"
        //---------------------------------------------------------------------
        
        testAnimation : function (){

            var myAnim = new Y.Anim({
                    node: '#testDiv',
                    to: {
                        width: 400
                    },
                    duration: 3,
                    easing: Y.Easing.easeOut
            });

            //assign oncomplete handler
            myAnim.on("end", function(){
            
                //tell the TestRunner to resume
                this.resume(function(){
                
                    Y.Assert.areEqual(document.getElementById("testDiv").offsetWidth, 400, "Width of the DIV should be 400.");
                
                });
            
            }, this, true);

            //start the animation
            myAnim.run();
            
            //wait until something happens
            this.wait();
        
        }
                    
    });
     
    //create the console
    var r = new Y.Console({
        verbose : true,
        newestOnTop : false
    });
    
    r.render('#testLogger');
    
    //create the logger
    Y.Test.Runner.add(Y.example.test.AsyncTestCase);

    //run the tests
    Y.Test.Runner.run();
});

</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>
